var hdadd = (function () {
	//"use strict";
    var addSum;
	this.init = function () {
		addSum = $("#txtAddSum");
		this.updateAdd();
        $("#btnAddCancel").click(function () {
            addSum.val("");
        });
        $("#btnAddSum").click(function () {
			var tempSum = "", str, i, temp;
			str = addSum.val().split(',');
			for (i = 0; i < str.length; i += 1) {
				tempSum += str[i];
			}
            temp = {
				Sum: parseFloat(tempSum),
                TakeSaving: $("#chFromSaving").is(':checked'),
                AccountID: parseInt($("#selAccountAddSum option:selected").val()),
                SavingID: parseInt($("#selSavingsAddSum option:selected").val())
			};
			data.addNewSum(temp);
            addSum.val("");
            hdcurrentstate.show();
        });


	};
    this.updateAdd = function(){
        data.getAccountList( function (results) {
            var i, num, str = "";
            num = results.rows.length;
            if (num !== 0) {
                for(i=0; i < num; i += 1){
                    str += "<option value='" + results.rows.item(i).AccountID + "'>" + results.rows.item(i).Name + "</option>";
                }
                $("#selAccountAddSum").html(str).selectmenu('refresh');
            }
        });
        data.getSavingsList(function (results) {
            var i, num, str = "";
            num = results.rows.length;
            if (num !== 0) {
                for(i=0; i < num; i += 1){
                    str += "<option value='" + results.rows.item(i).SavingID + "'>" + results.rows.item(i).Name + "</option>";
                }
                $("#selSavingsAddSum").html(str).selectmenu('refresh');
            }
        });
    };
	this.init();
	return this;
}(hdadd || {}));